import os
import cv2


def delele_time_stamp(source_video, target_video, x_scope=None, y_scope=None, save_fourcc_format='mp4v'):
    video_cap = cv2.VideoCapture(source_video)
    f_width = video_cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    f_height = video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    f_shape = (int(f_width), int(f_height))
    fps = int(video_cap.get(cv2.CAP_PROP_FPS))
    four_cc = cv2.VideoWriter_fourcc(*save_fourcc_format)
    video_writer = cv2.VideoWriter(target_video, four_cc, fps, f_shape)
    frame_num = 0
    while True:
        _, frame = video_cap.read()
        if frame is None:
            break
        frame_copy = frame.copy()
        frame_num += 1
        print("frame number ----->", frame_num)
        for x_coor in range(x_scope[0], x_scope[1] + 1):
            for y_coor in range(y_scope[0], y_scope[1] + 1):
                for channel in range(3):
                    frame_copy[y_coor, x_coor, channel] = frame[30, x_coor, channel]
        video_writer.write(frame_copy)
        # cv2.imshow("window", frame_copy)
        # cv2.waitKey(1000)
    video_writer.release()
    video_cap.release()


if __name__ == "__main__":
    # sample_01 = cv2.imread("../sample/03-01-10-47-C167_sec_57_135_1.jpg")
    # sample_02 = sample_01.copy()
    # print(type(sample_01))
    # print(sample_01.shape)
    # x_scope = [0, 720]
    # y_scope = [58, 110]
    # for x_coor in range(x_scope[0], x_scope[1] + 1):
    #     for y_coor in range(y_scope[0], y_scope[1] + 1):
    #         for channel in range(3):
    #             sample_02[y_coor, x_coor, channel] = sample_01[30, x_coor, channel]
    # cv2.imshow("sample_02", sample_02)
    # cv2.waitKey(0)
    ################################################################
    origin_video = r"/home/stark/algo-env/yolov7-MGN/data/sample-02/video_fragment/sample_03.mp4"
    destiny_video = r"/home/stark/algo-env/yolov7-MGN/data/sample.mp4"
    x_scope = [0, 720]
    y_scope = [58, 110]
    delele_time_stamp(origin_video, destiny_video, x_scope, y_scope)
